import {
  PersonModel
} from '../../models/hdd/personal.js'
let personModel = new PersonModel()
import {
  LoginModel
} from '../../models/hdd/login.js'
let loginModel = new LoginModel()
import {
  AuthModel
} from '../../models/hdd/authData.js'
let authModel = new AuthModel()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  pageLifetimes: {
    show() {
      wx.showLoading({
        mask: true
      })
      const personal = personModel.getPersonalData()
      personal.then(res => {
        wx.hideLoading()
        console.log(res)
        this.setData({
          personalData: res.data.data.data.company,
          FCompamyPhoto: res.data.data.data.company.platformAuthen.FCompamyPhoto ? res.data.data.data.company.platformAuthen.FCompamyPhoto : ''
        })
      })
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    personalData: '',
    FCompamyPhoto: '',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    pushToOrderList() {
      wx.navigateTo({
        url: '/pages/orderList/orderList',
      })
    },

    logout() {
      wx.showModal({
        showCancel: true,
        title: '提示',
        content: '确定要注销吗?',
        success(res) {
          if (res.confirm) {
            const logout = loginModel.logout()
            logout.then(res => {
              if (res.data.success) {
                wx.reLaunch({
                  url: '/pages/hdd-login/hdd-login',
                })
              }
            })
          }
        }
      })
    },

    pushToAuth() {
      wx.navigateTo({
        url: `/pages/auth/auth?FItEmpId=${this.data.personalData.FId}`,
      })
    },

    pushToPersonInfo() {
      wx.navigateTo({
        url: `/pages/personInfo/personInfo?personalData=${JSON.stringify(this.data.personalData)}`
      })
    },

    pushToEditPersonInfo() {
      wx.navigateTo({
        url: `/pages/companyDetail/companyDetail?fromPage=me&mobile=${this.data.personalData.FMobile}`,
      })
    }
  }
})
